<template>
	<view>
		<image :src="bg" class="imgbg"></image>
		<view class="title">分销申请填写</view>
		<view class="box">
			<view class="box2"></view>
			<view class="name">姓名：</view>
			<input class="ipt" placeholder="输入您的姓名" name="truename" v-model="truename"/>
			<view class="name">联系电话：</view>
			<input class="ipt" placeholder="输入您的手机号码" type="digit" name="mobile" v-model="mobile" maxlength="11" />
			<button class="btn" @click="apply" v-if="status==''||status=='fail'">立即申请</button>
			<button class="btn" v-if="status=='verifing'" style="background: #CCCCCC;">审核中</button>
			
		</view>
	</view>
</template>

<script>
	import {share,shareApply} from '../../apirequest/api.js';
	export default {
		data() {
			return {
				//姓名
				truename: '',
				//手机号
				mobile: '',
				bg:'',
				status:'',
				lock:0,
			}
		},
		onShow() {
			this.loadData();
		},
		methods: {
			//获取数据
			loadData: function () {
			  share({}).then((res) => {
			  		if(res.code == 1){
						this.info = res.data.info;
						if(this.info){
							if (this.info.status=='normal') {
								uni.showToast({
									title:'已申请，不可重复申请',
									icon:"error"
								})
								setTimeout(function(){
									uni.navigateBack({
										delta:0
									});
								},1000)
							}
							this.mobile = res.data.info.mobile;
							this.truename = res.data.info.truename;
							this.status = res.data.info.status;
							console.log(res.data.info.status)
						}
						this.bg = res.data.bg;
					} else{
						uni.showToast({
							title:res.msg,
							icon:"error"
						})
						setTimeout(function(){
							uni.navigateBack({
								delta:0
							});
						},1000)
					}
			  }).catch(err => {
			  	 console.log(err)
			  })
			  
			},
			//提交申请
			apply:function(){
				if (!this.truename) {
					uni.showToast({
						title:'请填写您的姓名',
						icon:"error"
					});
					return;
				}
				
				if (!this.mobile) {
					uni.showToast({
						title:'请填写您的联系方式',
						icon:"error"
					});
					return;
				}
				
				if(this.lock){
					return;
				}
				this.lock = 1;
				shareApply({mobile:this.mobile,truename:this.truename}).then((res) => {
					if(res.code == 1){
						uni.showToast({
							title:'提交成功，请等待审核',
							icon:"success"
						})
						setTimeout(function(){
							window.location.reload();
						},1000)
					} else{
						uni.showToast({
							title:res.msg,
							icon:"error"
						});this.lock = 0;
						
					}
				}).catch(err => {
					 console.log(err)
				})
				
			},
			
		}
	}
</script>

<style>
	page {
		font-size: 30rpx;
		color: #333;
	}

	.imgbg {
		position: fixed;
		width: 100%;
		height: 100%;

		object-fit: cover;
		top: 0;
		left: 0;
	}

	.title {
		text-align: center;
		color: #fff;
		font-size: 55rpx;
		margin: 13% 0;
		position: relative;
	}

	.box {
		position: relative;
		background: rgba(255, 255, 255, 0.5);
		border-radius: 10rpx;
		margin: 0 20rpx 0rpx 50rpx;
		padding: 0 30rpx 20rpx;
	}

	.box .box2 {
		width: 102%;
		height: 95%;
		position: absolute;
		background: rgba(255, 255, 255, 0.5);
		top: 3%;
		right: 10rpx;
		border-radius: 10rpx;
	}

	.box .name {
		font-size: 0.95rem;
		padding-top: 40px;
	
	}

	.box .ipt {
		background: #fff;
		border-radius: 40rpx;
		padding: 24rpx 10rpx;
		margin-top: 20rpx;
		font-size: 26rpx;
	}
	.box .btn{
		background: linear-gradient(45deg,#f56619,#fbb92b);
		color: #fff;
		border-radius: 50rpx;
		margin: 50rpx 0 20rpx;
		font-size: 1rem;
		padding: 10rpx 0;
	}
</style>
